﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class CheckDataList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userName"] == null || Session["roleID"] == null)
        {
            Response.Redirect("Login.aspx");
            Response.End();
        }        
        if (!Page.IsPostBack)
        {            
            BindToDdlYear();
            BindToFlowSteps();
        }

    }
    //绑定流程列表数据
    protected void BindToFlowSteps()
    {        
        RpFlowList.DataSource = pds();
        RpFlowList.DataBind();
    }
    private PagedDataSource pds()
    {
        int pageSize = 15;
        string LCtableName = "LC" + ddlYear.SelectedValue.ToString();
        string LCBZtableName = "LCBZ" + ddlYear.SelectedValue.ToString();
        string DataTableName = "JCZL" + ddlYear.SelectedValue.ToString();
        string userName = Session["userName"].ToString();
        string roleID = Session["roleID"].ToString();
        string userCondition = "";
        if (roleID != "1")
        {
            userCondition = " and LCBZ.OPERATORID='" + userName + "'";

        }
        string sqlString = "select * from " + LCtableName + " as LC inner join " + LCBZtableName + " as LCBZ on LC.TRUEFLOWID=LCBZ.TRUEFLOWID and LC.CURRENTSTEP=LCBZ.SEQ";
        sqlString += " where LC.STATUS='0'" + userCondition;
        sqlString += " order by LC.BEGINDATE desc";
        DBOperation DBO = new DBOperation();
        DataSet ds = DBO.GetDataSet(sqlString, "temp");
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables["temp"].DefaultView;
        pds.AllowPaging = true;//允许分页
        pds.PageSize = pageSize;//单页显示项数
        int CurrentPage = 0;
        if (Request.QueryString["page"] != null)
        {
            CurrentPage = Convert.ToInt32(Request.QueryString["page"]);
        }
        pds.CurrentPageIndex = CurrentPage;
        return pds;
    }
    //绑定数据到选择年份下拉列表
    private void BindToDdlYear()
    {
        BasicClass BC = new BasicClass();
        int currentYear = Convert.ToInt32(DateTime.Now.Year.ToString());
        Hashtable htYear = BC.GetDataYear();
        ddlYear.DataSource = htYear;
        ddlYear.DataTextField = "value";
        ddlYear.DataValueField = "key";
        ddlYear.DataBind();
        ddlYear.SelectedValue = currentYear.ToString();
    }
    protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindToFlowSteps();
    }
    protected void ddlp_SelectedIndexChanged(object sender, EventArgs e)
    {//脚模板中的下拉列表框更改时激发
        string pg = Convert.ToString((Convert.ToInt32(((DropDownList)sender).SelectedValue) - 1));//获取列表框当前选中项
        Response.Redirect("CheckDataList.aspx?page=" + pg);//页面转向
    }
        
    protected void RpFlowList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            DropDownList ddlp = (DropDownList)e.Item.FindControl("ddlp");

            HyperLink lpfirst = (HyperLink)e.Item.FindControl("hlfir");
            HyperLink lpprev = (HyperLink)e.Item.FindControl("hlp");
            HyperLink lpnext = (HyperLink)e.Item.FindControl("hln");
            HyperLink lplast = (HyperLink)e.Item.FindControl("hlla");

            pds().CurrentPageIndex = ddlp.SelectedIndex;

            int n = Convert.ToInt32(pds().PageCount);//n为分页数
            int i = Convert.ToInt32(pds().CurrentPageIndex);//i为当前页

            Label lblpc = (Label)e.Item.FindControl("lblpc");
            lblpc.Text = n.ToString();
            Label lblp = (Label)e.Item.FindControl("lblp");
            lblp.Text = Convert.ToString(pds().CurrentPageIndex + 1);

            if (!IsPostBack)
            {
                for (int j = 0; j < n; j++)
                {
                    ddlp.Items.Add(Convert.ToString(j + 1));
                }
            }

            if (i <= 0)
            {
                lpfirst.Enabled = false;
                lpprev.Enabled = false;
                lplast.Enabled = true;
                lpnext.Enabled = true;
            }
            else
            {
                lpprev.NavigateUrl = "?page=" + (i - 1);
            }
            if (i >= n - 1)
            {
                lpfirst.Enabled = true;
                lplast.Enabled = false;
                lpnext.Enabled = false;
                lpprev.Enabled = true;
            }
            else
            {
                lpnext.NavigateUrl = "?page=" + (i + 1);
            }

            lpfirst.NavigateUrl = "?page=0";//向本页传递参数page
            lplast.NavigateUrl = "?page=" + (n - 1);

            ddlp.SelectedIndex = Convert.ToInt32(pds().CurrentPageIndex);//更新下拉列表框中的当前选中页序号
        }
    }
}
